package pe.edu.unmsm.juegoia.view;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pe.edu.unmsm.juegoia.controller.JuegoController;
import pe.edu.unmsm.juegoia.controller.impl.JuegoTyAController;
import pe.edu.unmsm.juegoia.model.JuegoModel;
import pe.edu.unmsm.juegoia.model.JuegoTyAModel;
import pe.edu.unmsm.juegoia.model.MovimientoObserver;
import pe.edu.unmsm.juegoia.model.Posicion;
import pe.edu.unmsm.juegoia.model.TableroObserver;
import pe.edu.unmsm.juegoia.model.impl.JuegoTyAHHModel;
import pe.edu.unmsm.juegoia.model.impl.JuegoTyAHMModel;
import static pe.edu.unmsm.juegoia.model.impl.JuegoTyAHMModel.*;

/**
 *
 * @author Pablo & Marlon
 */
public class FrmPrincipal extends javax.swing.JFrame implements TableroObserver, MovimientoObserver {

    public static final int FICHA_ANCHO = 34;
    public static final int FICHA_LARGO = 34;
    public static final int INCREMENTO_DIMENSION_X = 27;
    public static final int INCREMENTO_DIMENSION_Y = -47;
    private JLabel[][] casilleros = new JLabel[7][7];
    private JuegoController controller;
    private JuegoTyAModel model;
    public int turnoTemporal = TURNO_JUGADOR_1;
    private int cont = 0;

    /**
     * Creates new form FrmPrincipal
     */
    public FrmPrincipal(JuegoController controller, JuegoTyAModel model) {
        this.controller = controller;
        this.model = model;
        this.model.registerObserver((TableroObserver) this);
        this.model.registerObserver((MovimientoObserver) this);
        initComponents();
        this.setLocationRelativeTo(null);
        this.getContentPane().setBackground(Color.WHITE);

        setUpCasilleros();

        this.setVisible(true);
    }

    private void setUpFichas() {
        controller.iniciarNuevoJuego();
    }

    private void setUpCasilleros() {
//        casilla = new JLabel();
//        casilla.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/fic2.jpg")));
//        casilla.setBounds(88,11, 34, 34);
//        pnlTablero.add(casilla, 1);

        //int tempPosX = 7, tempPosY = 152;
        int tempPosX = 27, tempPosY = 166;
        for (int i = 0; i < 4; i++) {
            casilleros[0][i] = new JLabel();
            casilleros[0][i].setIcon(null);
            casilleros[0][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[0][i], 0);
            casilleros[0][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }
        // x: + 20;   y: +14
//        tempPosX = 34;
//        tempPosY = 199;
        tempPosX = 54;
        tempPosY = 213;
        for (int i = 0; i < 5; i++) {
            casilleros[1][i] = new JLabel();
            casilleros[1][i].setIcon(null);
            casilleros[1][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[1][i], 0);
            casilleros[1][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }

//        tempPosX = 61;
//        tempPosY = 246;
        tempPosX = 81;
        tempPosY = 260;
        for (int i = 0; i < 6; i++) {
            casilleros[2][i] = new JLabel();
            casilleros[2][i].setIcon(null);
            casilleros[2][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[2][i], 0);
            casilleros[2][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }

//        tempPosX = 88;
//        tempPosY = 293;
        tempPosX = 108;
        tempPosY = 307;
        for (int i = 0; i < 7; i++) {
            casilleros[3][i] = new JLabel();
            casilleros[3][i].setIcon(null);
            casilleros[3][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[3][i], 0);
            casilleros[3][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }

//        tempPosX = 142;
//        tempPosY = 293;
        tempPosX = 162;
        tempPosY = 307;
        for (int i = 1; i < 7; i++) {
            casilleros[4][i] = new JLabel();
            casilleros[4][i].setIcon(null);
            casilleros[4][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[4][i], 0);
            casilleros[4][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }

//        tempPosX = 196;
//        tempPosY = 293;
        tempPosX = 213;
        tempPosY = 307;
        for (int i = 2; i < 7; i++) {
            casilleros[5][i] = new JLabel();
            casilleros[5][i].setIcon(null);
            casilleros[5][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[5][i], 0);
            casilleros[5][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }

//        tempPosX = 250;
//        tempPosY = 293;
        tempPosX = 270;
        tempPosY = 307;
        for (int i = 3; i < 7; i++) {
            casilleros[6][i] = new JLabel();
            casilleros[6][i].setIcon(null);
            casilleros[6][i].setBounds(tempPosX, tempPosY, FICHA_ANCHO, FICHA_LARGO);
            pnlTablero.add(casilleros[6][i], 0);
            casilleros[6][i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    casilleroSeleccionado(evt);
                }
            });
            tempPosX += INCREMENTO_DIMENSION_X;
            tempPosY += INCREMENTO_DIMENSION_Y;
        }
    }

    private void casilleroSeleccionado(MouseEvent evt) {
        JLabel lblCasillaSeleccionada = (JLabel) evt.getSource();

        int x = 0, y = 0;
        for (int i = 0; i < casilleros.length; i++) {
            for (int j = 0; j < casilleros[i].length; j++) {
                if (lblCasillaSeleccionada == casilleros[i][j]) {
                    x = i;
                    y = j;
                }
            }
        }

        controller.setPosicionSeleccionada(x, y);

        System.out.println("Casilla seleccionada: " + x + "," + y);
    }

    private void limpiarTarjetaMovimientos() {
        tblMovimientos = new javax.swing.JTable();

        tblMovimientos.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{
            "", "Blancas", "Rojas"
        }) {
            Class[] types = new Class[]{
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean[]{
                false, false, false
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });

        tblMovimientos.setColumnSelectionAllowed(true);

        tblMovimientos.getTableHeader().setReorderingAllowed(false);

        jScrollPane1.setViewportView(tblMovimientos);

        tblMovimientos.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    @Override
    public void updateTablero() {
        Integer[][] tablero = model.getTablero();
        Integer casillero;
        for (int i = 0; i < tablero.length; i++) {
            for (int j = 0; j < tablero[i].length; j++) {
                casillero = tablero[i][j];
                if (casillero != null) {
                    if (casillero == JuegoModel.JUGADOR_1) {
                        casilleros[i][j].setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/fic1.jpg")));
                    } else if (casillero == JuegoModel.JUGADOR_2) {
                        casilleros[i][j].setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/fic2.jpg")));
                    } else {
                        casilleros[i][j].setIcon(null);
                    }
                }
            }
        }

        int jugadorGanador = model.getJugadorGanador();

        if (jugadorGanador != 0) {
            if (jugadorGanador == JuegoModel.JUGADOR_1) {
                JOptionPane.showMessageDialog(this, "Felicitaciones,"
                        + " ganó el jugador BLANCO");
            } else if (jugadorGanador == JuegoModel.JUGADOR_2) {
                JOptionPane.showMessageDialog(this, "Felicitaciones, ganó el jugador"
                        + " ROJO");
            }
        }

        // updatear turno
        if (model.getJugadorTurnoActual() == TURNO_JUGADOR_1) {
            pnlJugador1.setBackground(new Color(133, 205, 131, 250));
            pnlJugador2.setBackground(Color.WHITE);

        } else {
            pnlJugador2.setBackground(new Color(133, 205, 131, 250));
            pnlJugador1.setBackground(Color.WHITE);

        }
        if (model.getJugadorTurnoActual() != turnoTemporal) {
            DefaultTableModel modelTable = (DefaultTableModel) tblMovimientos.getModel();
            if (turnoTemporal == JUGADOR_1) {
                modelTable.addRow(new Object[]{cont + 1, model.getMovimientoJ1(), ""});
            } else {
                modelTable.setValueAt(model.getMovimientoJ2(), cont, 2);
                //    System.out.println("Valor celda: " + modelTable.getValueAt(cont, cont));
                cont++;
            }

            turnoTemporal = (model.getJugadorTurnoActual() == TURNO_JUGADOR_2) ? TURNO_JUGADOR_2
                    : TURNO_JUGADOR_1;
        }
    }

    @Override
    public void updateMovimientos() {
        updateTablero();

        List<Posicion> posicionesPosibles = model.getMovimientosDisponibles();
        if (posicionesPosibles != null) {
            if (!posicionesPosibles.isEmpty()) {
                int x, y;
                for (Posicion posicion : posicionesPosibles) {
                    x = posicion.getPosX();
                    y = posicion.getPosY();
                    casilleros[x][y].setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/mov.jpg")));
                }
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlTablero = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        lblTablero = new javax.swing.JLabel();
        pnlJugador2 = new javax.swing.JPanel();
        lblFigJugador2 = new javax.swing.JLabel();
        pnlJugador1 = new javax.swing.JPanel();
        lblFigJugador1 = new javax.swing.JLabel();
        pnlMovimientos = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMovimientos = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnuitNuevoJuego = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Atletas vs. Tragonas");
        setBackground(new java.awt.Color(255, 255, 255));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("6");
        jLabel1.setBounds(356, 95, 20, 14);
        pnlTablero.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("G");
        jLabel2.setBounds(80, 314, 20, 14);
        pnlTablero.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("2");
        jLabel3.setBounds(191, 0, 20, 14);
        pnlTablero.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("3");
        jLabel4.setBounds(246, 0, 20, 14);
        pnlTablero.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("4");
        jLabel5.setBounds(300, 0, 20, 14);
        pnlTablero.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("7");
        jLabel6.setBounds(383, 144, 20, 14);
        pnlTablero.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("5");
        jLabel7.setBounds(330, 50, 20, 14);
        pnlTablero.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("1");
        jLabel8.setBounds(135, 0, 20, 14);
        pnlTablero.add(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("A");
        jLabel9.setBounds(80, 34, 20, 14);
        pnlTablero.add(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setText("B");
        jLabel10.setBounds(53, 83, 20, 14);
        pnlTablero.add(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("C");
        jLabel11.setBounds(28, 129, 20, 14);
        pnlTablero.add(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel12.setText("D");
        jLabel12.setBounds(0, 174, 20, 14);
        pnlTablero.add(jLabel12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setText("E");
        jLabel13.setBounds(28, 224, 20, 14);
        pnlTablero.add(jLabel13, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel14.setText("F");
        jLabel14.setBounds(53, 269, 20, 14);
        pnlTablero.add(jLabel14, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lblTablero.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/tablero.jpg"))); // NOI18N
        lblTablero.setBounds(20, 14, 373, 337);
        pnlTablero.add(lblTablero, javax.swing.JLayeredPane.DEFAULT_LAYER);

        pnlJugador2.setBackground(new java.awt.Color(255, 255, 255));
        pnlJugador2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Jugador 2", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Microsoft Sans Serif", 0, 12))); // NOI18N

        lblFigJugador2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblFigJugador2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/humano2.png"))); // NOI18N

        javax.swing.GroupLayout pnlJugador2Layout = new javax.swing.GroupLayout(pnlJugador2);
        pnlJugador2.setLayout(pnlJugador2Layout);
        pnlJugador2Layout.setHorizontalGroup(
            pnlJugador2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblFigJugador2, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
        );
        pnlJugador2Layout.setVerticalGroup(
            pnlJugador2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblFigJugador2, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pnlJugador1.setBackground(new java.awt.Color(255, 255, 255));
        pnlJugador1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Jugador 1", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Microsoft Sans Serif", 0, 12))); // NOI18N

        lblFigJugador1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblFigJugador1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/unmsm/juegoia/images/humano1.png"))); // NOI18N

        javax.swing.GroupLayout pnlJugador1Layout = new javax.swing.GroupLayout(pnlJugador1);
        pnlJugador1.setLayout(pnlJugador1Layout);
        pnlJugador1Layout.setHorizontalGroup(
            pnlJugador1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblFigJugador1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
        );
        pnlJugador1Layout.setVerticalGroup(
            pnlJugador1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblFigJugador1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pnlMovimientos.setBackground(new java.awt.Color(255, 255, 255));
        pnlMovimientos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tarjeta de movimientos", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Microsoft Sans Serif", 0, 12))); // NOI18N

        tblMovimientos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Blancas", "Rojas"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblMovimientos.setColumnSelectionAllowed(true);
        tblMovimientos.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblMovimientos);
        tblMovimientos.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        javax.swing.GroupLayout pnlMovimientosLayout = new javax.swing.GroupLayout(pnlMovimientos);
        pnlMovimientos.setLayout(pnlMovimientosLayout);
        pnlMovimientosLayout.setHorizontalGroup(
            pnlMovimientosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMovimientosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlMovimientosLayout.setVerticalGroup(
            pnlMovimientosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jMenu1.setText("Juego");

        mnuitNuevoJuego.setText("Nuevo juego HH");
        mnuitNuevoJuego.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuitNuevoJuegoActionPerformed(evt);
            }
        });
        jMenu1.add(mnuitNuevoJuego);

        jMenu3.setText("Nuevo Juego vs Maquina");

        jMenuItem2.setText("Principiante");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem2);

        jMenuItem3.setText("Intermedio");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem4.setText("Experto");
        jMenu3.add(jMenuItem4);

        jMenu1.add(jMenu3);

        jMenuItem1.setText("Salir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu4.setText("Acerca de");
        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(pnlJugador2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(pnlJugador1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlTablero, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlMovimientos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pnlMovimientos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlJugador2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(162, 162, 162)
                        .addComponent(pnlJugador1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(pnlTablero))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuitNuevoJuegoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuitNuevoJuegoActionPerformed
        cont = 0;
        turnoTemporal = JUGADOR_1;
        model = new JuegoTyAHHModel();
        limpiarTarjetaMovimientos();
        this.model.registerObserver((TableroObserver)this);
        this.model.registerObserver((MovimientoObserver)this);
        controller = new JuegoTyAController(model, this);
        controller.iniciarNuevoJuego();
        this.setVisible(true);
    }//GEN-LAST:event_mnuitNuevoJuegoActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        cont = 0;
        turnoTemporal = JUGADOR_1;
        model = new JuegoTyAHMModel();
        model.setNivelMaquina(0);
        limpiarTarjetaMovimientos();

        this.model.registerObserver((TableroObserver) this);
        this.model.registerObserver((MovimientoObserver) this);

        controller = new JuegoTyAController(model, this);

        controller.iniciarNuevoJuego();

        this.setVisible(true);

    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        cont = 0;
        turnoTemporal = JUGADOR_1;
        model = new JuegoTyAHMModel();
        model.setNivelMaquina(1);
        limpiarTarjetaMovimientos();

        this.model.registerObserver((TableroObserver) this);
        this.model.registerObserver((MovimientoObserver) this);

        controller = new JuegoTyAController(model, this);

        controller.iniciarNuevoJuego();

        this.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed
    /**
     * @param args the command line arguments
     */
    /*public static void main(String args[]) {

     try {
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
     if ("Nimbus".equals(info.getName())) {
     javax.swing.UIManager.setLookAndFeel(info.getClassName());
     break;
     }
     }
     } catch (ClassNotFoundException ex) {
     java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (InstantiationException ex) {
     java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (IllegalAccessException ex) {
     java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (javax.swing.UnsupportedLookAndFeelException ex) {
     java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }


     // Create and display the form
     java.awt.EventQueue.invokeLater(new Runnable() {
     public void run() {
     new FrmPrincipal().setVisible(true);
     }
     });
     }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblFigJugador1;
    private javax.swing.JLabel lblFigJugador2;
    private javax.swing.JLabel lblTablero;
    private javax.swing.JMenuItem mnuitNuevoJuego;
    private javax.swing.JPanel pnlJugador1;
    private javax.swing.JPanel pnlJugador2;
    private javax.swing.JPanel pnlMovimientos;
    private javax.swing.JLayeredPane pnlTablero;
    private javax.swing.JTable tblMovimientos;
    // End of variables declaration//GEN-END:variables
}
